#!/bin/bash


# 判断系统类型
if [ ! -z "$(command -v yum)" ]; then
  #echo "This system uses yum (likely Red Hat/CentOS family)."
  SYSTEM_TYPE='Redhat'
elif [ ! -z "$(command -v apt-get)" ] || [ ! -z "$(command -v apt)" ]; then
  #echo "This system uses apt (likely Debian/Ubuntu family)."
  SYSTEM_TYPE='Debian_Ubuntu'
else
  #echo "Could not determine which package manager to use."
  SYSTEM_TYPE='Unknow'
fi


download_zookeeper(){
  echo "------------------------ zookeeper downloading... ----------------------------"
  curl -O https://dlcdn.apache.org/zookeeper/zookeeper-3.8.4/apache-zookeeper-3.8.4-bin.tar.gz
}

download_clickhouse(){
   if [ $SYSTEM_TYPE = "Redhat" ];then
      echo "------------------------ clickhouse-client downloading... ----------------------------"
      curl -O https://packages.clickhouse.com/rpm/stable/clickhouse-client-23.8.12.13.x86_64.rpm
      echo "------------------------ clickhouse-common-static downloading... ----------------------------"
      curl -O https://packages.clickhouse.com/rpm/stable/clickhouse-common-static-23.8.12.13.x86_64.rpm
      echo "------------------------ clickhouse-server downloading... ----------------------------"
      curl -O https://packages.clickhouse.com/rpm/stable/clickhouse-server-23.8.12.13.x86_64.rpm
   elif [ $SYSTEM_TYPE = "Debian_Ubuntu" ];then
      echo "------------------------ clickhouse-client downloading... ----------------------------"
      curl -O https://packages.clickhouse.com/deb/pool/main/c/clickhouse/clickhouse-client_23.8.12.13_amd64.deb
      echo "------------------------ clickhouse-common-static downloading... ----------------------------"
      curl -O https://packages.clickhouse.com/deb/pool/main/c/clickhouse/clickhouse-common-static_23.8.12.13_amd64.deb
      echo "------------------------ clickhouse-server downloading... ----------------------------"
      curl -O https://packages.clickhouse.com/deb/pool/main/c/clickhouse/clickhouse-server_23.8.12.13_amd64.deb
   else
    echo "UnKonw System!"
    exit 1
   fi  
}


do_download(){
cd soft
download_zookeeper
download_clickhouse
}


do_download
